//
//  NSFileManager+Utility.m
//  DGUtilityKit
//
//  Created by Jinxiao on 11/30/13.
//  Copyright (c) 2013 debugeek. All rights reserved.
//

#import "NSFileManager+Utility.h"

@implementation NSFileManager (Utility)

- (void)deleteAllFilesAtPath:(NSString *)path
{
    NSError *error = nil;
    NSArray *files = [self contentsOfDirectoryAtPath:path error:&error];
    for(NSString *file in files)
    {
        [self removeItemAtPath:[path stringByAppendingPathComponent:file] error:&error];
    }
}

- (NSString *)documentDirectory
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *directory = [paths objectAtIndex:0];
    return directory;
}

- (NSString *)libraryDirectory
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *directory = [paths objectAtIndex:0];
    return directory;
}

- (NSString *)cachesDirectory
{
    return [[self libraryDirectory] stringByAppendingPathComponent:@"Caches"];
}

@end